<template>
	<view class="logins">
		<nav-bar isBack title="授权登录"></nav-bar>

		<!-- 顶部 -->
		<view class="login">
			<view class="login_top">
				<image src="https://manager.ryz1620.com/static/ryzLogo/logo-2.png"></image>
				<view class="login-name">融易装</view>
				<view class="login-cont">我们需要您的授权，更好的为您服务</view>
			</view>
		</view>
		<!-- 登录 -->
		<view class="login_btn">
		  <!-- #ifdef MP-WEIXIN -->	
			<template v-if="qyLoginType">
				<button class="weixin" @click="isDefaults" v-if="isDefault==0"><text>企业微信授权登录</text></button>
				<button class="weixin" v-if="isDefault==1" @click="qyLogin"><text>企业微信授权登录</text></button>
			</template>
			<template v-else>
				<button class="weixin" @click="isDefaults" v-if="isDefault==0"><text>微信授权登录</text></button>
				<button class="weixin" v-if="isDefault==1 && canIUse" @click="getUserPhone"><text>微信授权登录</text></button>
			<!-- 	<view class="phone" @click="isDefaults" v-if="isDefault==0"><text>手机号授权登录</text></view>
				 <view class="phone" @click="phonelogin()" v-if="isDefault==1"><text>手机号授权登录</text></view> -->
			</template>
			<!-- #endif -->
			<!-- #ifdef APP-PLUS || H5 -->
			 <button class="weixin" @click="isDefaults" v-if="isDefault==0"><text>微信授权登录</text></button>
			 <button class="weixin" v-if="isDefault==1" type="primary" open-type="getUserInfo" @click="appwx_login_event"><text>微信授权登录</text></button>
			 <view class="phone" @click="isDefaults" v-if="isDefault==0"><text>手机号授权登录</text></view>
			 <view class="phone" @click="phonelogin()" v-if="isDefault==1"><text>手机号授权登录</text></view>
			<!-- #endif -->
		</view>
		<view class="radio-cell">
			<view class="radio">
				<radio @click="radioChange" :checked="isDefault==1" style="transform: scale(0.75);" color="#3D444B"
					:data-checked="isDefault"></radio>我已阅读并同意<text @click="agent">《用户授权协议》</text>
			</view>	
		</view>
		<!-- #ifdef MP-WEIXIN -->	
		<!-- <view v-if="openid" class="alert">
			<view class="auth">
				<view class="apply">
					<span class="">需要获取您的手机权限</span>
					<p>(请开启手机权限)</p>
				</view>
				<button class="confirm" v-if="canIUse" open-type="getPhoneNumber"
					@getphonenumber="getPhoneNumber">确认</button>
			</view>
		</view> -->
		<view v-if="openid" class="alert">
			<view class="conmtauth">
				<view class="conmt">
					<view class="call">
						<text class="left-text">手机号</text>
						<input type="number" placeholder="请输入手机号" v-model="mobile"/>
					</view>
					<view class="call">
						<text class="left-text">验证码</text>
						<input type="number" placeholder="请输入验证码" v-model="sms_code"/>
						<text class="right-text"  v-if="time===60"@click="getCodeEvent">获取验证码</text>
						<text class="right-text"  v-if="time!==60" style="color: #999;">{{time}}s</text>
					</view>
					<view class="loginbtn" @click="userBindMobileWeChat">绑定手机号码</view>
				</view>
			</view>
		</view>
        <!-- #endif -->
		<!-- #ifdef APP-PLUS || H5 -->
		<view v-if="openid" class="alert">
			<view class="conmtauth">
				<view class="conmt">
					<view class="call">
						<text class="left-text">手机号</text>
						<input type="number" placeholder="请输入手机号" v-model="mobile"/>
					</view>
					<view class="call">
						<text class="left-text">验证码</text>
						<input type="number" placeholder="请输入验证码" v-model="sms_code"/>
						<text class="right-text"  v-if="time===60"@click="getCodeEvent">获取验证码</text>
						<text class="right-text"  v-if="time!==60" style="color: #999;">{{time}}s</text>
					</view>
					<view class="loginbtn" @click="userBindMobile">绑定手机号码</view>
				</view>
			</view>
		</view>
		<!-- #endif -->
	</view>
</template>

<script>
	import navBar from "@/components/navBar/navBar.vue"
	import service_enter from '@/service/login.js'
	import URL from '@/config/url.js'
	// #ifdef MP-WEIXIN
	var gioConfig = require("@/components/GrowingIO/gioConfig.js").default;
	// #endif
	export default {
		components: {
			navBar
		},

		data() {
			return {
				isDefault: 0,
				// 登录信息
				token: null, // token
				isBindMobile: null, // 是否绑定手机号
				userMobile: null, // 用户手机号
				userId: null, // 用户userId
				role: '',
				openid: '',
				nickName: '',
				avatarUrl: '',
				canIUse: uni.canIUse('button.open-type.getUserInfo'),
				qyLoginType:false,
				appopenid:'',
				mobile:'',
				sms_code:'',
				time:60,
				timer:null,
				goods:'',
				ww_share_code:''
			}
		},

		onLoad(op) {
			if(op.goods){
				this.goods = op.goods
				this.ww_share_code = op.ww_share_code
			}
			//#ifdef MP-WEIXIN
				const sinfo = wx.getSystemInfoSync();
				console.log(sinfo,'信息')
				if(sinfo.environment == 'wxwork'){
					this.qyLoginType = true
				}
			//#endif
		},
        onUnload() {
        	clearInterval(this.timer)
        	this.timer = null;
        },
		methods: {
			timeInterval(){
				this.time = this.time - 1;
				this.timer = setInterval(()=>{
					if(this.time-1<1){
						clearInterval(this.timer)
						this.timer = null;
						this.time = 60
					}else{
						this.time = this.time - 1;
					}
				},1000)
			},
			getCodeEvent(){
					let phonenum = /^1[23456789]\d{9}$/.test(this.mobile);
					if(!this.mobile){
						uni.showToast({ title: '请输入手机号', icon: 'none' });
						return
					}
					if(!phonenum){
						uni.showToast({ title: '请输入正确的手机号码', icon: 'none' });
						return
					}
					
					service_enter.getPhonecode({
						mobile:this.mobile
					}).then(res=>{
						if(res.code === 1){
							this.timeInterval();
							uni.showToast({ title: '已发送验证码！', icon: 'none' });
						}else{
							uni.showToast({ title: res.msg, icon: 'none' });
						}
						
					})
			},
			userBindMobile(){
				let phonenum = /^1[23456789]\d{9}$/.test(this.mobile);
				if(!this.mobile){
					uni.showToast({ title: '请输入手机号', icon: 'none' });
					return
				}
				if(!phonenum){
					uni.showToast({ title: '请输入正确的手机号码', icon: 'none' });
					return
				}
				if(!this.sms_code){
					uni.showToast({ title: '请输入验证码', icon: 'none' });
					return
				}
				this.$utils.showLoading()
				service_enter.bindUserPhone({
					mobile:this.mobile,
					smscode:this.sms_code,
					openid: this.appopenid,
					nickName: this.nickName,
					avatarUrl: this.avatarUrl,
				}).then(res=>{
					this.$utils.hideLoading()
					if (res.code == 1) {
						let data = res.data
						let mobile = res.data.mobile
						// 保存数据
						let token = data.token.access_token
						let userId = data.user_id
						let userMobile = data.mobile
						this.openid = ''
						// 保存数据
						this.token = token
						this.userMobile = userMobile
						this.userId = userId
						uni.setStorageSync('token', token);
						uni.setStorageSync('userMobile', userMobile);
						uni.setStorageSync('userId', userId);
						uni.setStorageSync('token', token);
						this.$store.commit('index/SET_token', token)
						this.$store.commit('index/SET_userMobile', userMobile)
						this.$store.commit('index/SET_userId', userId)
						this.isBindMobile = true
						this.userMobile = mobile
						this.$store.commit('index/SET_isBindMobile', true)
						let Router = uni.getStorageSync('Router')
						let urls = '/' + Router
						console.log(urls)
						if(urls=='/pages/home/index/index'){
							uni.switchTab({
									url: '/pages/home/index/index'
							 })
						}else if (urls=='/pages/discovery/index/index'){
							uni.switchTab({
									url: '/pages/discovery/index/index'
							 })
						}else if (urls=='/pages/mall/index/index'){
							uni.switchTab({
									url: '/pages/mall/index/index'
							 })
						}else if (urls=='/pages/my/index'){
							uni.switchTab({
									url: '/pages/my/index'
							 })
						}
						else if (urls=='/pages/home/index/list'){
							uni.switchTab({
									url: '/pages/home/index/list'
							 })
						}else{
							uni.redirectTo({
								url: urls
							});
						}
					} else {
						this.$utils.hideLoading()
						this.$utils.showErr({
							title: res.msg
						})
					}
				})
			},
			phonelogin() {
				uni.navigateTo({
					url: '/pages_login/pages/login/phonelogin/index?goods=' + this.goods + '&ww_share_code=' + this.ww_share_code,
				});
			},
			agent() {
				uni.navigateTo({
					url: '/pages_login/pages/login/agreement/index',
				});
			},
			radioChange(t) {
				if (t.currentTarget.dataset.checked == 0) {
					this.isDefault = 1
				} else {
					this.isDefault = 0
				}
			},
			isDefaults() {
				uni.showToast({
					title: '您还未勾选授权协议！',
					icon: 'none'
				})
			},
			
			// 企业微信登录
			qyLogin(){
				let that = this
				let single_id = uni.getStorageSync('single_id')
				let root = uni.getStorageSync('root') == "true" ? true : false
				let product_id = uni.getStorageSync('id')
				let gid = uni.getStorageSync('gid')
				let u = uni.getStorageSync('u')
				let follow_id = uni.getStorageSync('follow_id')
				wx.qy.login({
					success:res=>{
						console.log(res,'企业微信登录')
						if(res.code){
							service_enter.getToken({
								code: res.code,
								nickName: that.nickName,
								avatarUrl: that.avatarUrl,
								sence:'qywx'
							}).then(res=>{
								console.log(res,'企业微信登录--')
								uni.hideLoading()
								if (res.code == 1) {
									// console.log(res);
									let data = res.data
									let openid = res.data.openid
									// that.openid = openid
									// let userId = data.wxres.userid
									// 获取用户审核信息
									if (!openid) {
										// let isBindMobile = data.bind_mobile_status ==
										// 	1 ? true : false; // 用户是否绑定手机号
										let token = data.token.access_token
										let userId = data.user_id
										// let userMobile = data.mobile
										let nowOpenid = res.data.wxres.openid
										// 设置登陆growingio上传信息
										// #ifdef MP-WEIXIN
										gioConfig.forceLogin = true
										gio('setConfig', gioConfig);
										gio('identify', res.data.wxres.openid, res.data
											.wxres.unionid)
										gio('setUserId', res.data.wxres.openid);
										gio('setUser', {
											id: res.data.wxres.openid,
											name: that.nickName
										});
										gio('userID', res.data.wxres.openid)
										// #endif
										uni.setStorageSync('unionid', res.data.wxres
											.unionid)
										// 保存数据
										that.token = token
										// that.isBindMobile = isBindMobile
										// that.userMobile = userMobile
										that.userId = userId
										uni.setStorageSync('token', token);
										// uni.setStorageSync('userMobile', userMobile);
										uni.setStorageSync('userId', userId);
										uni.setStorageSync('token', token);
										uni.setStorageSync('nowOpenid', nowOpenid);
										that.$store.commit('index/SET_token', token)
										that.$store.commit('index/SET_nowOpenid',nowOpenid)
										that.$store.commit('index/SET_userId', userId)
										that.$utils.hideLoading()
										let Router = uni.getStorageSync('Router')
										let urls = '/' + Router
										console.log(urls)
										if(urls=='/pages/home/index/index'){
											uni.switchTab({
													url: '/pages/home/index/index'
											 })
										}else if (urls=='/pages/discovery/index/index'){
											uni.switchTab({
													url: '/pages/discovery/index/index'
											 })
										}else if (urls=='/pages/mall/index/index'){
											uni.switchTab({
													url: '/pages/mall/index/index'
											 })
										}else if (urls=='/pages/my/index'){
											uni.switchTab({
													url: '/pages/my/index'
											 })
										}
										else if (urls=='/pages/home/index/list'){
											uni.switchTab({
													url: '/pages/home/index/list'
											 })
										}else{
											uni.redirectTo({
												url: urls
											});
										}
										// if (single_id) {
										// 	if (root) {
										// 		uni.redirectTo({
										// 			url: `/pages_mall/pages/mall/userPay/userPay?single_id=${single_id}&root=true`
										// 		})
										// 	} else {
										// 		uni.redirectTo({
										// 			url: '/pages_mall/pages/mall/userPay/userPay?single_id=' + single_id
										// 		})
										// 	}
										// } else if (this.goods) {
										// 	console.log(product_id, '详情页商品id')
										// 	uni.redirectTo({
										// 		url: `/pages_mall/pages/mall/goods_details/goods_details?id=${product_id}&gid=${gid}&u=${u}&ww_share_code=${this.ww_share_code}`
										// 	})
										// } else {
										// 	uni.switchTab({
										// 			url: '/pages/home/index/index'
										// 	});
										// }
									} else {
										uni.showToast({
											title:'你还不是该企业成员',
											icon:'none'
										})
										let nowOpenid = res.data.openid
										that.$store.commit('index/SET_nowOpenid',
											nowOpenid)
										// 设置登陆growingio上传信息
										// #ifdef MP-WEIXIN
										gioConfig.forceLogin = true
										gio('setConfig', gioConfig);
										gio('identify', res.data.openid, res.data
											.unionid)
										gio('setUserId', res.data.openid);
										gio('setUser', {
											id: res.data.openid,
											name: that.nickName
										});
										gio('userID', res.data.openid)
										// #endif
										uni.setStorageSync('unionid', res.data.unionid)

									}
								} else {
									that.$utils.hideLoading()
									that.$utils.showErr({
										title: res.msg
									})
								}
							})
						}
					}
				})
			},
			
			// 微信小程序绑定手机号
			userBindMobileWeChat(){
				this.$utils.hideLoading()
				let phonenum = /^1[23456789]\d{9}$/.test(this.mobile);
				if(!this.mobile){
					uni.showToast({ title: '请输入手机号', icon: 'none' });
					return
				}
				if(!phonenum){
					uni.showToast({ title: '请输入正确的手机号码', icon: 'none' });
					return
				}
				if(!this.sms_code){
					uni.showToast({ title: '请输入验证码', icon: 'none' });
					return
				}
				let single_id = uni.getStorageSync('single_id')
				let root = uni.getStorageSync('root') == "true" ? true : false
				let product_id = uni.getStorageSync('id')
				let NewName = uni.getStorageSync('NewName')
				let gid = uni.getStorageSync('gid')
				let u = uni.getStorageSync('u')
				let shareuId = this.$store.state.index.shareuId || '';
				
				this.$utils.showLoading({
					title:'绑定中...'
				})
				service_enter.bindUserPhone({
					mobile:this.mobile,
					smscode:this.sms_code,
					openid: this.openid,
					share_uid: shareuId,
					nickName: this.nickName,
					avatarUrl: this.avatarUrl,
				}).then(res=>{
					this.$utils.hideLoading()
					console.log(res)
					if (res.code == 1) {
						let data = res.data
						let mobile = res.data.mobile
						// 保存数据
						let token = data.token.access_token
						let userId = data.user_id
						let userMobile = data.mobile
						this.openid = ''
						// 保存数据
						this.token = token
						this.userMobile = userMobile
						this.userId = userId
						uni.setStorageSync('token', token);
						uni.setStorageSync('userMobile', userMobile);
						uni.setStorageSync('userId', userId);
						uni.setStorageSync('token', token);
						uni.setStorageSync('nowOpenid', nowOpenid);
						this.$store.commit('index/SET_token', token)
						this.$store.commit('index/SET_userMobile', userMobile)
						this.$store.commit('index/SET_userId', userId)
						this.isBindMobile = true
						this.userMobile = mobile
						this.$store.commit('index/SET_isBindMobile', true)
						let Router = uni.getStorageSync('Router')
						let urls = '/' + Router
						console.log(urls)
						if(urls=='/pages/home/index/index'){
							uni.switchTab({
									url: '/pages/home/index/index'
							 })
						}else if (urls=='/pages/discovery/index/index'){
							uni.switchTab({
									url: '/pages/discovery/index/index'
							 })
						}else if (urls=='/pages/mall/index/index'){
							uni.switchTab({
									url: '/pages/mall/index/index'
							 })
						}else if (urls=='/pages/my/index'){
							uni.switchTab({
									url: '/pages/my/index'
							 })
						}
						else if (urls=='/pages/home/index/list'){
							uni.switchTab({
									url: '/pages/home/index/list'
							 })
						}else{
							uni.redirectTo({
								url: urls
							});
						}
					} else {
						this.$utils.hideLoading()
						this.$utils.showErr({
							title: res.msg
						})
					}
				})
			},
			
			// 原微信获取手机号（官方弃用）
			getPhoneNumber(e) {
				this.$utils.hideLoading()
				let single_id = uni.getStorageSync('single_id')
				let root = uni.getStorageSync('root') == "true" ? true : false
				let product_id = uni.getStorageSync('id')
				let NewName = uni.getStorageSync('NewName')
				let gid = uni.getStorageSync('gid')
				let u = uni.getStorageSync('u')
				let encryptedData = e.detail.encryptedData
				let iv = e.detail.iv
				let page = e.currentTarget.dataset.page
				let shareuId = this.$store.state.index.shareuId || ''
				if (encryptedData && iv) {
					this.$utils.showLoading({
						title: '绑定中...'
					})
					service_enter.bindUserPhone({
							encryptedData: encryptedData,
							iv: iv,
							openid: this.openid,
							share_uid: shareuId,
							nickName: this.nickName,
							avatarUrl: this.avatarUrl,
						})
						.then(res => {
							this.$utils.hideLoading()
							console.log(res)
							if (res.code == 1) {
								let data = res.data
								let mobile = res.data.mobile
								// 保存数据
								let token = data.token.access_token
								let userId = data.user_id
								let userMobile = data.mobile
								this.openid = ''
								// 保存数据
								this.token = token
								this.userMobile = userMobile
								this.userId = userId
								uni.setStorageSync('token', token);
								uni.setStorageSync('userMobile', userMobile);
								uni.setStorageSync('userId', userId);
								uni.setStorageSync('token', token);
								uni.setStorageSync('nowOpenid', nowOpenid);
								this.$store.commit('index/SET_token', token)
								this.$store.commit('index/SET_userMobile', userMobile)
								this.$store.commit('index/SET_userId', userId)
								this.isBindMobile = true
								this.userMobile = mobile
								this.$store.commit('index/SET_isBindMobile', true)
								let Router = uni.getStorageSync('Router')
								let urls = '/' + Router
								console.log(urls)
								if(urls=='/pages/home/index/index'){
									uni.switchTab({
											url: '/pages/home/index/index'
									 })
								}else if (urls=='/pages/discovery/index/index'){
									uni.switchTab({
											url: '/pages/discovery/index/index'
									 })
								}else if (urls=='/pages/mall/index/index'){
									uni.switchTab({
											url: '/pages/mall/index/index'
									 })
								}else if (urls=='/pages/my/index'){
									uni.switchTab({
											url: '/pages/my/index'
									 })
								}
								else if (urls=='/pages/home/index/list'){
									uni.switchTab({
											url: '/pages/home/index/list'
									 })
								}else{
									uni.redirectTo({
										url: urls
									});
								}
								// console.log(single_id,product_id)
								// 跳转页面
								// console.log(NewName);
								// if (single_id) {
								// 	if (root) {
								// 		uni.redirectTo({
								// 			url: `/pages_mall/pages/mall/userPay/userPay?single_id=${single_id}&root=true`
								// 		})
								// 	} else {
								// 		uni.redirectTo({
								// 			url: '/pages_mall/pages/mall/userPay/userPay?single_id=' +
								// 				single_id
								// 		})
								// 	}
								// } else if (this.goods) {
								// 	uni.redirectTo({
								// 		url: `/pages_mall/pages/mall/goods_details/goods_details?id=${product_id}&gid=${gid}&u=${u}&ww_share_code=${this.ww_share_code}`
								// 	})
								// } else if (product_id && NewName) {
								// 	uni.redirectTo({
								// 		url: `/pages_mall/pages/mall/goods_details/GoodsShareDetails?id=${product_id}&gid=${gid}&u=${u}`
								// 	})
								// } else {
								// 	// uni.switchTab({
								// 	// 	url: '/pages/home/index/index'
								// 	// });
								// 	uni.navigateBack({
										
								// 	})
								// }
							} else {
								this.$utils.hideLoading()
								this.$utils.showErr({
									title: res.msg
								})
							}
						})
				}
			},
			getUserPhone() {
				let that = this
				let single_id = uni.getStorageSync('single_id')
				let root = uni.getStorageSync('root') == "true" ? true : false
				let product_id = uni.getStorageSync('id')
				let gid = uni.getStorageSync('gid')
				let u = uni.getStorageSync('u')
				let NewName = uni.getStorageSync('NewName')
				let shareuId = uni.getStorageSync('shareuId')
				console.log(shareuId,'====')
				// console.log(product_id,gid,u,'============')
				uni.getUserProfile({
					desc: '用于完善会员资料',
					lang: 'zh_CN',
					success: e => {
						uni.setStorageSync('userInfo', e.userInfo)
						// console.log('-----------------------------');
						// console.log(e);
						// 统计获取用户信息
						gio('setVisitor', e.userInfo);
						that.nickName = e.userInfo.nickName
						that.avatarUrl = e.userInfo.avatarUrl
						that.$utils.login({
							success: (res) => {
								// console.log(res);
								service_enter.getToken({
										code: res.code,
										nickName: that.nickName,
										avatarUrl: that.avatarUrl,
										sence:'',
										wx_access_token:'',
										unionid:'',
										openid:'',
										share_id:shareuId
									})
									.then(res => {
										uni.hideLoading()
										if (res.code == 1) {
											// console.log(res);
											let data = res.data
											let openid = res.data.openid
											that.openid = openid
											// 获取用户审核信息
											if (!openid) {
												let isBindMobile = data.bind_mobile_status ==
													1 ? true : false // 用户是否绑定手机号
												let token = data.token.access_token
												let userId = data.user_id
												let userMobile = data.mobile
												let nowOpenid = res.data.wxres.openid
												// 设置登陆growingio上传信息
												// #ifdef MP-WEIXIN
												gioConfig.forceLogin = true
												gio('setConfig', gioConfig);
												gio('identify', res.data.wxres.openid, res.data
													.wxres.unionid)
												gio('setUserId', res.data.wxres.openid);
												gio('setUser', {
													id: res.data.wxres.openid,
													name: that.nickName
												});
												gio('userID', res.data.wxres.openid)
												// #endif
												uni.setStorageSync('unionid', res.data.wxres
													.unionid)
												// 保存数据
												that.token = token
												that.isBindMobile = isBindMobile
												that.userMobile = userMobile
												that.userId = userId
												uni.setStorageSync('userMobile', userMobile);
												uni.setStorageSync('userId', userId);
												uni.setStorageSync('token', token);
												uni.setStorageSync('nowOpenid', nowOpenid);
												that.$store.commit('index/SET_token', token)
												that.$store.commit('index/SET_isBindMobile',
													isBindMobile)
												that.$store.commit('index/SET_userMobile',
													userMobile)
												that.$store.commit('index/SET_nowOpenid',
													nowOpenid)
												that.$store.commit('index/SET_userId', userId)
												that.$utils.hideLoading()
												// #ifdef MP-WEIXIN
												this.$utils.gitsetting()
												// #endif
												let Router = uni.getStorageSync('Router')
												let urls = '/' + Router
												console.log(urls)
												if(urls=='/pages/home/index/index'){
													uni.switchTab({
															url: '/pages/home/index/index'
													 })
												}else if (urls=='/pages/discovery/index/index'){
													uni.switchTab({
															url: '/pages/discovery/index/index'
													 })
												}else if (urls=='/pages/mall/index/index'){
													uni.switchTab({
															url: '/pages/mall/index/index'
													 })
												}else if (urls=='/pages/my/index'){
													uni.switchTab({
															url: '/pages/my/index'
													 })
												}
												else if (urls=='/pages/home/index/list'){
													uni.switchTab({
															url: '/pages/home/index/list'
													 })
												}else{
													uni.redirectTo({
														url: urls
													});
												}
												// if (single_id) {
												// 	if (root) {
												// 		uni.redirectTo({
												// 			url: `/pages_mall/pages/mall/userPay/userPay?single_id=${single_id}&root=true`
												// 		})
												// 	} else {
												// 		uni.redirectTo({
												// 			url: '/pages_mall/pages/mall/userPay/userPay?single_id=' +
												// 				single_id
												// 		})
												// 	}
												// } else if (this.goods) {
												// 	uni.redirectTo({
												// 		url: `/pages_mall/pages/mall/goods_details/goods_details?id=${product_id}&gid=${gid}&u=${u}&ww_share_code=${this.ww_share_code}`
												// 	})
												// } else if (product_id && NewName) {
												// 	uni.redirectTo({
												// 		url: `/pages_mall/pages/mall/goods_details/GoodsShareDetails?id=${product_id}&gid=${gid}&u=${u}`
												// 	})
												// } else {
												// 	// uni.switchTab({
												// 	// 	url: '/pages/home/index/index'
												// 	// });
												// 	uni.navigateBack({
														
												// 	})
												// }
											} else {
												let nowOpenid = res.data.openid
												that.$store.commit('index/SET_nowOpenid',
													nowOpenid)
												// 设置登陆growingio上传信息
												// #ifdef MP-WEIXIN
												gioConfig.forceLogin = true
												gio('setConfig', gioConfig);
												gio('identify', res.data.openid, res.data
													.unionid)
												gio('setUserId', res.data.openid);
												gio('setUser', {
													id: res.data.openid,
													name: that.nickName
												});
												gio('userID', res.data.openid)
												// #endif
												uni.setStorageSync('unionid', res.data.unionid)

											}
										} else {
											that.$utils.hideLoading()
											that.$utils.showErr({
												title: res.msg
											})
										}
									})
							}
						})
					}
				})
				// uni.showLoading({title: '加载中',mask:true});
			},
			appwx_login_event() {
				let that = this
				let single_id = uni.getStorageSync('single_id')
				let root = uni.getStorageSync('root') == "true" ? true : false
				let product_id = uni.getStorageSync('id')
				let gid = uni.getStorageSync('gid')
				let u = uni.getStorageSync('u')
				let NewName = uni.getStorageSync('NewName')
				let shareuId = uni.getStorageSync('shareuId')
				console.log(shareuId,'====')
				// console.log(product_id,gid,u,'============')
				uni.login({
					provider: 'weixin',
							success: (r) => {
								let wxopenid = r.authResult.openid
								let wxunionid = r.authResult.unionid
								let wxaccess_token = r.authResult.access_token
								this.appopenid = r.authResult.openid
								uni.getUserInfo({
									success: (ves) => {
										uni.setStorageSync('userInfo', ves.userInfo)
										that.nickName = ves.userInfo.nickName
										that.avatarUrl = ves.userInfo.avatarUrl
										service_enter.getToken({
												code: '',
												nickName: that.nickName,
												avatarUrl: that.avatarUrl,
												wx_access_token:wxaccess_token,
												unionid:wxunionid,
												openid:wxopenid,
												sence:'',
												share_id:shareuId
											})
											.then(res => {
												uni.hideLoading()
												if (res.code == 1) {
													// console.log(res);
													let data = res.data
													let openid = res.data.openid
													that.openid = openid
													// 获取用户审核信息
													if (!openid) {
														let isBindMobile = data.bind_mobile_status ==
															1 ? true : false // 用户是否绑定手机号
														let token = data.token.access_token
														let userId = data.user_id
														let userMobile = data.mobile
														let nowOpenid = res.data.wxres.openid
														// 设置登陆growingio上传信息
														uni.setStorageSync('unionid', res.data.wxres
															.unionid)
														// 保存数据
														that.token = token
														that.isBindMobile = isBindMobile
														that.userMobile = userMobile
														that.userId = userId
														uni.setStorageSync('token', token);
														uni.setStorageSync('userMobile', isBindMobile);
														uni.setStorageSync('userId', userId);
														uni.setStorageSync('token', token);
														uni.setStorageSync('nowOpenid', nowOpenid);
														that.$store.commit('index/SET_token', token)
														that.$store.commit('index/SET_isBindMobile',
															isBindMobile)
														that.$store.commit('index/SET_userMobile',
															userMobile)
														that.$store.commit('index/SET_nowOpenid',
															nowOpenid)
														that.$store.commit('index/SET_userId', userId)
														that.$utils.hideLoading()
														
														let Router = uni.getStorageSync('Router')
														let urls = '/' + Router
														console.log(urls)
														if(urls=='/pages/home/index/index'){
															uni.switchTab({
																	url: '/pages/home/index/index'
															 })
														}else if (urls=='/pages/discovery/index/index'){
															uni.switchTab({
																	url: '/pages/discovery/index/index'
															 })
														}else if (urls=='/pages/mall/index/index'){
															uni.switchTab({
																	url: '/pages/mall/index/index'
															 })
														}else if (urls=='/pages/my/index'){
															uni.switchTab({
																	url: '/pages/my/index'
															 })
														}
														else if (urls=='/pages/home/index/list'){
															uni.switchTab({
																	url: '/pages/home/index/list'
															 })
														}else{
															uni.redirectTo({
																url: urls
															});
														}
														// if (single_id) {
														// 	if (root) {
														// 		uni.redirectTo({
														// 			url: `/pages_mall/pages/mall/userPay/userPay?single_id=${single_id}&root=true`
														// 		})
														// 	} else {
														// 		uni.redirectTo({
														// 			url: '/pages_mall/pages/mall/userPay/userPay?single_id=' +
														// 				single_id
														// 		})
														// 	}
														// } else if (this.goods) {
														// 	uni.redirectTo({
														// 		url: `/pages_mall/pages/mall/goods_details/goods_details?id=${product_id}&gid=${gid}&u=${u}&ww_share_code=${this.ww_share_code}`
														// 	})
														// } else if (product_id && NewName) {
														// 	uni.redirectTo({
														// 		url: `/pages_mall/pages/mall/goods_details/GoodsShareDetails?id=${product_id}&gid=${gid}&u=${u}`
														// 	})
														// } else {
															
														// 	// uni.switchTab({
														// 	// 	url: '/pages/home/index/index'
														// 	// });
														// 	uni.navigateBack({
																
														// 	})
														// }
													} else {
														let nowOpenid = res.data.openid
														that.$store.commit('index/SET_nowOpenid',
															nowOpenid)
														uni.setStorageSync('unionid', res.data.unionid)
					
													}
												} else {
													that.$utils.hideLoading()
													that.$utils.showErr({
														title: res.msg
													})
												}
											})
											
										}
									})
											
						       }
						})	
			},

		}
	}
</script>

<style lang="scss" scoped>
	.logins {
		width: 100vw;
		height: 100vh;
		background: #fff;
		display: flex;
		flex-flow: column;
	}

	.login {
		padding-top: 88rpx;
		padding-bottom: 20rpx;

		.login_top {
			text-align: center;

			image {
				display: block;
				margin: auto;
				width: 250rpx;
				height: 250rpx;
			}

			.login-name {
				font-size: 36rpx;
				font-weight: bold;
				color: #0A0605;
				padding: 20rpx;
			}

			.login-cont {
				font-size: 28rpx;
				color: #505050;
			}
		}
	}

	.login_btn {
		padding: 70rpx 50rpx;

		.weixin {
			line-height: 88rpx;
			border-radius: 44rpx;
			text-align: center;
			background: #3D444B;
			font-size: 36rpx;
			color: #fff;

			text {
				display: inline-block;
				line-height: 88rpx;
				padding-left: 60rpx;
				background: url(@/static/login/weixin.png) no-repeat left center;
				background-size: 48rpx;
			}
		}

		.phone {
			line-height: 88rpx;
			border-radius: 44rpx;
			text-align: center;
			border: 1px #505050 solid;
			font-size: 36rpx;
			color: #505050;
			margin-top: 30rpx;

			text {
				display: inline-block;
				line-height: 88rpx;
				padding-left: 60rpx;
				background: url(@/static/login/phone.png) no-repeat left center;
				background-size: 48rpx;
			}
		}
	}

	.radio-cell {
		text-align: center;
		color: #A0A0A0;

		text {
			color: #505050;
		}
	}

	.alert {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		overflow: hidden;
		outline: 0;
		-webkit-overflow-scrolling: touch;
		background-color: rgb(0, 0, 0);
		filter: alpha(opacity=60);
		background-color: rgba(0, 0, 0, 0.6);
		z-index: 9999;

		.auth {
			position: absolute;
			top: 50%;
			left: 50%;
			width: 80%;
			height: 340rpx;
			border-radius: 20rpx;
			overflow: hidden;
			transform: translate(-50%, -50%);
			background: #fff;
			display: flex;
			flex-direction: column;

			.apply {
				margin: 0rpx auto;
				padding: 60rpx 40rpx;
				flex: 1;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: space-between;
				font-size: 34rpx;
				color: rgb(34, 34, 34);

				p {
					font-size: 30rpx
				}
			}

			.confirm {
				border-top: 1rpx solid rgb(221, 221, 221);
				text-align: center;
				height: 100rpx;
				width: 100%;
				line-height: 100rpx;
				font-size: 34rpx;
				color: rgb(255, 145, 37);
			}
		}
	}
.conmtauth {
	position: absolute;
	top: 50%;
	left: 50%;
	width: 80%;
	height: 580rpx;
	border-radius: 20rpx;
	overflow: hidden;
	transform: translate(-50%, -50%);
	background: #fff;
	display: flex;
	flex-direction: column;
}
.conmt{
		background: #fff;
		padding: 30rpx;
		padding-bottom: 80rpx;
		border-radius: 0 0 20rpx 20rpx;
		.call{
			position: relative;
			.left-text{
				display: block;
				font-size: 30rpx;
				font-weight: bold;
				line-height: 70rpx;
			}
			input{
				background: #F8F8F8;
				height: 80rpx;
				line-height: 80rpx;
				padding: 0 20rpx;
				margin-bottom: 50rpx;
			}
			.right-text{
				display:inline-block;
				text-align: center;
				position: absolute;
				right: 20rpx;
				bottom: 0;
				line-height: 80rpx;
				color: #DBA954;
				z-index: 99;
			}
		}
		.loginbtn{
			line-height: 88rpx;
			border-radius: 44rpx;
			text-align: center;
			background: #3D444B;
			font-size: 32rpx;
			color: #fff;
		}
}	
</style>
